<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html >
<html>
<head>
<title>查看网点区域</title>
	<script type="text/javascript" src="http://api.map.baidu.com/library/TextIconOverlay/1.2/src/TextIconOverlay_min.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/library/MarkerClusterer/1.2/src/MarkerClusterer_min.js"></script>
<script type="text/javascript">

//定义地图, 
var map = new BMap.Map("myMap"); // 创建Map实例
var centerPoint = new BMap.Point(121.485966, 31.239957); //初始化地图，中心点为上海中心点
map.centerAndZoom(centerPoint, 13); // 初始化地图,设置中心点坐标和地图级别
var opts = {             //设置左上角控件，地图缩放类型
	type : BMAP_NAVIGATION_CONTROL_SMALL
};
map.addControl(new BMap.NavigationControl(opts)); //添加左上角缩放控件 
map.enableScrollWheelZoom(); //可滚动缩放
map.disableDoubleClickZoom(); //关闭双击放大

var myGeo = new BMap.Geocoder();
var index = 0;
var list=${list};
document.getElementById("addressNum").value=list.length;
//var localSearch = new BMap.LocalSearch(map);
//localSearch.enableAutoViewport(); //允许自动调节窗体大小
var errorN=0;
var success=0;
//var keyword=null;
	bdGEO();

	
	var markers = [];
	var markerClusterer=null;

function bdGEO(){
	if(index<list.length)
	{
		var add = list[index].fromCityName+list[index].fromDistrictName+list[index].fromAddress;
		geocodeSearch(add);
		index++;
	}else if(index >=list.length)
	{
	    add="地址已完";	
	    geocodeSearch(add);
	}

}

/* for(var i=0;i<list.length;i++)
	{
		
	    keyword =list[i].fromCityName+list[i].fromAddress;
	 	//alert(keyword);
	 	localSearch.setSearchCompleteCallback(function (searchResult) {
	    var poi = searchResult.getPoi(0);
	    if(poi==null)
	    {  	errorN++;
	    	document.getElementById("errorNum").value=errorN;
	    }else{		    	
	    	document.getElementById('load_address').style.display = "none";	    	
	    	//map.centerAndZoom(poi.point, 13);
		    var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat));  // 创建标注，为要查询的地方对应的经纬度
		    map.addOverlay(marker);	
		    success++;
	  		document.getElementById("successNum").value=success;
		    //marker.setAnimation(BMAP_ANIMATION_BOUNCE);
	    }		   
		});
	 	localSearch.search(keyword); 	
	} */
	
function geocodeSearch(add){
	 if("地址已完"==add)
	{
		document.getElementById('load_address').style.display = "none";	 
		
	}else{
		if(index < list.length){
			setTimeout(window.bdGEO,100);
		}
		myGeo.getPoint(add, function(point){
			if (point) {
				var address = new BMap.Point(point.lng, point.lat);
				addMarker(address,new BMap.Label(index+":"+add,{offset:new BMap.Size(20,-10)}));
				 success++;
			  	document.getElementById("successNum").value=success;
			}
		},list[index].fromProvinceName);
	}
	
}

/*  //编写自定义函数,创建标注
function addMarker(point,label){
	var marker = new BMap.Marker(point);
	map.addOverlay(marker);
	//marker.setLabel(label);
}  */

 //编写自定义函数,创建标注
function addMarker(point,label){
	var marker = new BMap.Marker(point);
	map.addOverlay(marker);
	 markers.push(marker);
	//map.addOverlay(marker);
	//marker.setLabel(label);
} 

//编写自定义函数,创建标注
function juhe(){
	
	
	 markerClusterer = new BMapLib.MarkerClusterer(map, {markers:markers});
	//map.addOverlay(marker);
	//marker.setLabel(label);
} 

	
</script>
</head>
<body>
<div id="JScharts_div"></div>

	<div id="outside_div">
		
		<form id="month_search" onsubmit="return navTabSearch(this);" action="mapForOrders.action?toResult=searchOrders&rightId=${rightId}" method="post">
			<div class="pageHeader">
				<input type="hidden" name="init" value=0>
				<div class="searchBar">
					<table class="searchContent">
						<tr>
						<td>开始时间: 
								   <input id="searchCompany_startTime" type="text" class="date" name="startTime" value="${startTime}"
									readonly="readonly" />
						</td>				

						<td>结束时间: <input id="searchCompany_endTime" type="text" class="date" name="endTime"  value="${endTime}"
									readonly="readonly" />
						</td>
						
<!-- 						<td>错误地址: <input disabled="disabled" id="errorNum" type="text" name="errorAddress" />
						</td> -->
						
						<td>查询地址数: <input disabled="disabled" id="successNum" type="text" name="success" />
						</td>
						
						<td>地址总数: <input disabled="disabled" id="addressNum" type="text" name="errorAddress" />
						</td>
						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td>
								<div class="buttonActive">
									<div class="buttonContent">
										<button type="submit" >查询</button>
									</div>
								</div>
								<div class="buttonActive">
									<div class="buttonContent">
										<button type="button" onclick="juhe()">点聚合</button>
									</div>
								</div>
						</td>
					</tr>
			
				</table>
			</div>
		</div>
	</form>

		<div class="pageContent">			
				<div class="panelBar">
					<ul class="toolBar">

					</ul>
				</div>
		</div>		
			<div class="pageFormContent" layoutH="86">
						
						<div id="load_address" style="width:900px;height:30px;color:black;background:#77787b">
						Loading .....
						<br>
						查询地址中，请稍后！
						</div>
						<div id="myMap" style="width: 900px; height: 550px;">
									
						</div>
						
					
			</div>	
		</div>
</body>
</html>
